package sns.action;

import java.util.LinkedList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Comment;
import sns.bean.User;
import sns.dao.MblogDao;
import sns.service.CommentService;

import com.opensymphony.xwork2.Action;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ShowCommentAction extends ActionSupport {
	// injection
	CommentService commentService;
	MblogDao mblogDao;
	// pass in
	private Long mblogId;
	// return value
	private List<Comment> commentList;
	private List<User> userList;

	private Long mId;

	@Transactional
	public String execute() {

		userList = new LinkedList<User>();
		System.out.println("##########################mblog id is (from get): "
				+ mblogId);
		commentList = commentService.getCommentOfMblog(mblogDao
				.getMblogById(mblogId));
		System.out.println("###################### the size of commentList"
				+ commentList.size());
		for (Comment comment : commentList) {

			User user = comment.getPublisher();
			System.out.println("The comment is " + comment.getCommentTxt()
					+ " and the user is "
					+ comment.getPublisher().getNickname());
			userList.add(user);
		}
		mId = mblogId;
		return Action.SUCCESS;
	}

	public List<Comment> getCommentList() {
		return commentList;
	}

	public Long getmId() {
		return mId;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}

	public void setMblogDao(MblogDao mblogDao) {
		this.mblogDao = mblogDao;
	}

	public void setMblogId(Long mblogId) {
		this.mblogId = mblogId;
	}

	public List<User> getUserList() {
		return userList;
	}

}
